class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        if (s.length() <= 1) {
            return s.length();
        }

        int n = s.length();
        vector<int> count(256, 0);
        int ans = 0;

        for (int i = 0, j = 0; i < n; ++i) {
            ++count[s[i]];
            while (count[s[i]] > 1) {
                --count[s[j]];
                ++j;
            }
            ans = max(ans, i - j + 1);
        }
        return ans;

    }
};
